function submitForm(){
	if(!isReadyToSubmitRefraction()){
		return;
	}
	$('#btnSave').hide();
	$('#btnSaveAndPrint').hide();
	$('#divEditMessageBarLoading').show();
	$('#wantPrint').val(0);
	$('form#frmRefractionEdit').submit();
}

function submitFormAndPrint(){
	if(!isReadyToSubmitRefraction()){
		return;
	}
	$('#btnSave').hide();
	$('#btnSaveAndPrint').hide();
	$('#divEditMessageBarLoading').show();
	$('#wantPrint').val(1);
	$('form#frmRefractionEdit').submit();
}

function showMessage(response, status){
	if(status=='success' && response.saved){
		$('#lblEditMessage').css('color', 'green').text(_("Save successful"));
		$('#refractionId').val(response.refId);
		$('#divEditMessageBarLoading').hide();
		$('#btnSave').show();
		$('#btnSaveAndPrint').show();
		if ($('#wantPrint').val() == 1) {
			printRef('vi');
		}
	} else {
		$('#lblEditMessage').css('color', 'red').text(_("Fail! Please check the required fields"));
		$('#divEditMessageBarLoading').hide();
		$('#btnSave').show();
		$('#btnSaveAndPrint').show();
	}
}

$(document).ready(function(){
	 var options = { 
        success: showMessage,
        url:  $('#frmRefractionEdit').attr('action')+'?set_ajax_view',
        dataType:  'json'      
    }; 
    $('#frmRefractionEdit').ajaxForm(options); 
});
	

function isReadyToSubmitRefraction(){	
	return true;
}

function printRef(lang){
	var checked	=	$('#printSignature').is(':checked');
	if (checked) {
		checked='yes';
	} else {
		checked='no';
	}
	printRefraction($('#recordId').val(), checked, lang);
}